<template>
	<view>
		<u-navbar title="账号管理" :status-bar="false" safe-area-inset-top :placeholder="true" :autoBack="true">
		</u-navbar>
		<view>
			<scroll-view scroll-y style="height: 88vh;" @scrolltolower="handleScrolltolower">
				<view class="list" v-for="(item,index) in list">
					<view class="list-item">
						<view class="list-left" @click="handleClickItem(item)">
							<view class="list-top">{{item.bankName}}</view>
							<view class="list-name">开户名称：{{item.accountName}}</view>
							<view class="list-cardNo">银行卡号：{{item.bankCardNo}}</view>
						</view>
						<view>
							<u-icon size="20" color="#2979ff" name="edit-pen" @click="edit(item)"></u-icon>
						</view>
					</view>
				</view>
			</scroll-view>
			<view class="btn-view">
				<view class="btn" @click="toAddAndEdit">
					添加账号
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageParams: {
					pageSize: 10,
					pageNum: 1
				},
				list: [],
				total: 0,
			}
		},
		onLoad(options) {
			uni.$on('refreshPage', () => {
				this.pageParams.pageNum = 1;
				this.getList(true)
			});
			this.getList();
		},
		methods: {
			handleClickItem(item) {
				console.log(item);
				uni.navigateBack({
					success() {
						uni.$emit("accountItem", item);
					}
				});
			},
			getList(isEmpty = false) {
				this.api.bankAccountPage(this.pageParams).then(res => {
					console.log(res);
					if (isEmpty) {
						this.list = [];
					}
					this.total = res.data.total;
					if (this.list.length < this.total) {
						this.list = this.list.concat(res.data.rows);
					} else {

					}
				})
			},
			edit(item) {
				uni.navigateTo({
					url: "/pages/accountMan/addAndEdit?type=edit&id=" + item.id
				})
			},
			handleScrolltolower() {
				if (this.list.length < this.total) {
					this.pageParams.pageNum += 1;
					this.getList();
				}
			},
			toAddAndEdit() {
				uni.redirectTo({
					url: "/pages/accountMan/addAndEdit?type=add"
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	page {
		background-color: #F6F6F6;
	}

	.list {
		// margin: 10rpx;

		&-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;
			margin: 20rpx;
		}

		&-left {
			flex: 1;
		}

		&-top {
			font-size: 28rpx;
			font-weight: bold;
			margin-top: 10rpx;
		}

		&-name {
			font-size: 24rpx;
			margin-top: 10rpx;
			color: #909399;
		}

		&-cardNo {
			font-size: 24rpx;
			margin-top: 10rpx;
			color: #909399;
		}
	}

	.btn-view {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 20rpx;

		.btn {
			padding: 20rpx;
			width: 80%;
			background-color: #2979ff;
			text-align: center;
			color: #fff;
			border-radius: 50rpx;
		}
	}
</style>